<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-dojo-tags" prefix="sx" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>青鸟租房 - 用户注册</title>
<sx:head debug="true" cache="false" compressed="false" />
<link type="text/css" rel="stylesheet" href="css/style.css" />
<script type="text/javascript" src="scripts/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="scripts/function.js"></script>
<script type="text/javascript">
$(function(){
	$("form :input").blur(function (){
		$parent = $(this).parent();
		$parent.find(".error").remove();
		if ($(this).is("#username")){
			if (this.value.length < 3) {
				var errorMsg = "请输入至少三位的用户名";
				$parent.append("<span class='error'>" + errorMsg + "</span>");
			} else {
				$.post("ajax/existUser.action",$("#username").serialize(),function(data){
					var result = data;
					if (result!="") {
						var errorMsg = result;
						$parent.append("<span class='error'>" + errorMsg + "</span>");
					}
				},"json");
			}
		}
		if ($(this).is("#password")) {
			if (this.value.length < 6) {
				var errorMsg = "请输入至少六位的密码";
				$parent.append("<span class='error'>" + errorMsg + "</span>");
			}
		}
		if ($(this).is("#password2")) {
			if (this.value != $("#password").val()) {
				var errorMsg = "两次输入的密码不一致";
				$parent.append("<span class='error'>" + errorMsg + "</span>");
			}
		}
		if ($(this).is("#telephone")){
			if (this.value.length < 8) {
				var errorMsg = "请输入至少8位的电话";
				$parent.append("<span class='error'>" + errorMsg + "</span>");
			}
		}
		if ($(this).is("#name")){
			if (this.value.length < 2) {
				var errorMsg = "请输入至少2位的用户姓名";
				$parent.append("<span class='error'>" + errorMsg + "</span>");
			}
		}
	});
	$("form").submit(function(){
		$("form :input").trigger("blur");
		var numError = $(".error").length;
		return numError == 0 ? true : false;
	});
});
</script>
</head>
<body>
<div id="header" class="wrap">
	<div id="logo"><img src="images/logo.gif" /></div>
</div>
<div id="regLogin" class="wrap">
	<div class="dialog">
		<dl class="clearfix">
			<dt>新用户注册</dt>
			<dd class="past">填写个人信息</dd>
		</dl>
		<div class="box">
			<form action="register.action" method="post">
				<div class="infos">
					<table class="field">
						<tr>
							<td class="field">用 户 名：</td>
							<td><input id="username" type="text" class="text" name="userName" /> </td>
						</tr>
						<tr>
							<td class="field">密　　码：</td>
							<td><input id="password" type="password" class="text" name="password" /></td>
						</tr>
						<tr>
							<td class="field">确认密码：</td>
							<td><input id="password2" type="password" class="text" name="password2" /> </td>
						</tr>
						<tr>
							<td class="field">电　　话：</td>
							<td><input id="telephone" type="text" class="text" name="telephone" /> </td>
						</tr>
						<tr>
							<td class="field">用户姓名：</td>
							<td><input id="name" type="text" class="text" name="name" /> </td>				
						</tr>
					</table>
					<div class="buttons"><input type="submit" name="submit" value="立即注册" /></div>
				</div>
			</form>
		</div>
	</div>
</div>
<div id="footer" class="wrap">
	<dl>
    	<dt>青鸟租房 &copy; 2010 北大青鸟 京ICP证1000001号</dt>
        <dd>关于我们 · 联系方式 · 意见反馈 · 帮助中心</dd>
    </dl>
</div>
</body>
</html>

